package org.teremail.mailbox;

/**
 * Data object for a folder that is stored in the database.
 * 
 * @author Michael Barker
 *
 */
public class FolderDO {

    private final String id;
    private Path path;
    private MailboxDO mailbox;
    private String name;
    private final int version;

    public FolderDO(String id, Path path, int version, MailboxDO mailbox) {
        this.id = id;
        this.path = path;
        setName(path);
        this.version = version;
        this.mailbox = mailbox;
    }
    
    public FolderDO(Path path, MailboxDO mailbox) {
        this(null, path, 0, mailbox);
    }
    
    public FolderDO(String id, FolderDO inbox) {
        this(id, inbox.path, inbox.version, inbox.mailbox);
    }
    
    public String getId() {
        return id;
    }

    private void setName(Path path) {
        name = path.last();
    }

    public String getName() {
        return name;
    }

    public MailboxDO getMailbox() {
        return mailbox;
    }

    public Path getPath() {
        return path;
    }

    public void setPath(Path path) {
        this.path = path;
        setName(path);
    }
    

}
